package com.shop.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket getDocket(){
        //创建docket对象并指定文档风格
        Docket docket=new Docket(DocumentationType.SWAGGER_2);
        //创建工厂
        ApiInfoBuilder apiInfoBuilder=new ApiInfoBuilder();
        //生成文档标题
        apiInfoBuilder.title("网上购物系统前端接口")
        //生成文档说明
                .description("此文档详细说明了网上购物系统前端接口的规范")
        //生成文档版本号
                .version("v 1.0.0");
        //通过工厂生成ApiInfo对象
        ApiInfo apiInfo=apiInfoBuilder.build();
        //指定生成文档封面信息
        docket.apiInfo(apiInfo)
                .select()
        //指定目录下的类生成接口文档
                .apis(RequestHandlerSelectors.basePackage("com.shop.controller"))
        //为当前目录下的所有请求生成接口文档
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}
